from itsdangerous import TimedJSONWebSignatureSerializer,BadData
from django.conf import  settings
def get_access_token_by_openid(openid):
    serializer=TimedJSONWebSignatureSerializer(secret_key=settings.SECRET_KEY,expires_in=600)
    access_token=serializer.dumps(openid).decode()
    return access_token

def get_openid(access_token):
    serializer=TimedJSONWebSignatureSerializer(secret_key=settings.SECRET_KEY,expires_in=600)
    #反序列化得到的是一个字典
    try:
        openid=serializer.loads(access_token)
    except BadData:
        return None
    else:
        return openid
